package com.yonyou.pmclouds.procedureinspect.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.yonyou.pmclouds.ApplicationConsts;
import com.yonyou.pmclouds.basecom.exception.BusinessException;
import com.yonyou.pmclouds.outter.user.UserInfoQuery;
import com.yonyou.pmclouds.processinspect.entity.ProcedureInspectBodyVO;
import com.yonyou.pmclouds.processinspect.entity.ProcedureInspectVO;
import com.yonyou.pmclouds.processinspect.rmiitf.ProcedureInspectRemoteService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
@RequestMapping(value="/procedureinspect/ref")
public class ProcedureInspectRefController {

	@Reference(version = ApplicationConsts.APPLICATION_VERSION)
	private ProcedureInspectRemoteService procedureInspectService;
	@Autowired
	private UserInfoQuery userQuery;

	/**
	 * 根据pk获取工序报验数据
	 *
	 * @param pkBill
	 * @return com.yonyou.pmclouds.processinspect.entity.ProcedureInspectVO
	 * @author yzx
	 * @date 2018/5/29 20:23
	 */
	@RequestMapping(value = "/getProcedureInspect")
	public ProcedureInspectVO getProcedureInspect(String pkBill) throws BusinessException {
		if (StringUtils.isEmpty(pkBill)) {
			return new ProcedureInspectVO();
		}
		ProcedureInspectVO procedureInspectVO = getProcedureInspectVO(pkBill);
		return procedureInspectVO;
	}

	private ProcedureInspectVO getProcedureInspectVO(String pkBill) throws BusinessException {
		ProcedureInspectVO procedureInspectVO = procedureInspectService.queryPrcInspectDetail(pkBill);

		userQuery.tranUserInfoField(new ProcedureInspectVO[]{procedureInspectVO},
				new String[]{ProcedureInspectVO.CREATOR, ProcedureInspectVO.ACCEPTOR},
				new String[]{ProcedureInspectVO.CREATORNAME, ProcedureInspectVO.ACCEPTORNAME});
		userQuery.tranUserInfoField(procedureInspectVO.getBodyVOs(),
				new String[]{ProcedureInspectBodyVO.RECORD_CREATOR},
				new String[]{ProcedureInspectBodyVO.RECORD_CREATOR_NAME});
		return procedureInspectVO;
	}

}
